Passed
Pull Request — master (#312)
by
unknown
03:23 queued 01:23
created

global.setup.ts ➔ globalSetup   A

Complexity

Conditions 1

Size

Total Lines 9
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 9
c 0
b 0
f 0
rs 10
cc 1
1
import { expect, firefox, type FullConfig, type Browser } from "@playwright/test";
2
3
import { STATE_AUTHENTICATED } from "./constants.js";
4
5
export default async function globalSetup(config: FullConfig): Promise<void> {
6
  const browser = await firefox.launch({
7
    headless: true,
8
  });
9
10
  await saveAuthenticatedState(browser, config, "[email protected]", "john", STATE_AUTHENTICATED);
11
12
  await browser.close();
13
}
14
15
async function saveAuthenticatedState(
16
  browser: Browser,
17
  config: FullConfig,
18
  email: string,
19
  password: string,
20
  path: string
21
) {
22
  const page = await browser.newPage({
23
    baseURL: config.projects[0].use.baseURL,
24
  });
25
  await page.goto("/kit/login");
26
27
  await page.getByLabel("Adresse email").fill(email);
28
  await page.getByLabel("Mot de passe").fill(password);
29
  await page.getByText("Se connecter").click();
30
31
  const response = await page.waitForResponse("**/api/login");
32
  expect(response.status()).toBe(201);
33
34
  await page.context().storageState({ path });
35
36
  await page.close();
37
}
38